home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: April 17, 1997
- // Author: mgr
- //
- // Description:
- // The alignPreset() procedure executes an align curve/surface operation
- // on a pair of curves/surfaces based on the align option vars. In general
- // if you have n curves/surfaces selected, only the last 2 curves/surfaces
- // would be aligned.
- //
- // Input Arguments:
- // None.
- //
- // Return Value:
- // None.
- //
-
- proc string pieceTogetherAlignCmd(
- int $history,
- int $replaceOriginal,
- int $attach,
- int $keepMultKnots,
- int $positionalType,
- int $doTangent,
- int $tangentType,
- int $doCurvature,
- float $tangentScale1,
- float $tangentScale2,
- float $curvatureScale1,
- float $curvatureScale2 )
- //
- // Description :
- // Piece together an align command.
- //
- {
- string $cmd = "";
- // $cmd = "align ";
-
- // construction history
- $cmd = $cmd + " -ch ";
- if ( $history == 1 ) $cmd = $cmd + "on";
- else $cmd = $cmd + "off";
-
- // replace original
- if ( $replaceOriginal == 1 ) $cmd = $cmd + " -rpo on";
- else $cmd = $cmd + " -rpo off";
-
- // attach
- if ( $attach == 1 )
- {
- $cmd = $cmd + " -at true";
- if ( $keepMultKnots == 1 ) $cmd = $cmd + " -kmk true";
- else $cmd = $cmd + " -kmk false";
- }
- else
- {
- // when attach is off, keep multiple knots has no meaning
- $cmd = $cmd + " -at false -kmk false";
- }
-
- // positional continuity type
- $cmd = $cmd + " -pct " + $positionalType;
-
- // tangent continuity
- if ( $doTangent == 1 )
- {
- $cmd = $cmd + " -tc true -tct " + $tangentType + " -ts1 " + $tangentScale1 + " -ts2 " + $tangentScale2;
- if ( $doCurvature == 1 ) $cmd = $cmd + " -cc true -cs1 " + $curvatureScale1 + " -cs2 " + $curvatureScale2;
- else $cmd = $cmd + " -cc false";
- }
- else
- {
- // tangent continuity is off so curvature continuity does not apply
- $cmd = $cmd + " -tc false -cc false";
- }
-
- return $cmd;
-
- }
-
- global proc alignPreset(
- int $history,
- int $replaceOriginal,
- int $attach,
- int $keepMultKnots,
- int $positionalType,
- int $doTangent,
- int $tangentType,
- int $doCurvature,
- float $tangentScale1,
- float $tangentScale2,
- float $curvatureScale1,
- float $curvatureScale2 )
- //
- // align with the preset options.
- // Use this proc when operation dragged to Shelf.
- //
- {
- string $cmd = pieceTogetherAlignCmd( $history, $replaceOriginal, $attach, $keepMultKnots, $positionalType, $doTangent, $tangentType, $doCurvature, $tangentScale1, $tangentScale2, $curvatureScale1, $curvatureScale2 );
-
- int $nitems = 2;
- $cmd = appendToCmdPlaceHoldersForSelectionItems( $cmd, $nitems );
-
- // Get the list of nurbs curves/surfaces selected.
- //
- global int $gSelectNurbsCurvesBit;
- global int $gSelectCurvesOnSurfacesBit;
- global int $gSelectNurbsSurfacesBit;
- global int $gSelectIsoparmsBit;
- global int $gSelectCurveParmPointsBit;
- global int $gSelectEditPointsBit;
- string $surfacesList[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectIsoparmsBit`;
- string $curvesList[] = `filterExpand -ex true -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit -sm $gSelectCurveParmPointsBit -sm $gSelectEditPointsBit`;
-
- int $numSurfaces = size($surfacesList);
- int $numCurves = size($curvesList);
- if ( $numSurfaces + $numCurves == 0 )
- {
- error("No curves or surfaces selected to align. You must select pairs of curves or surfaces.");
- }
- else if ( $numCurves == 1 && $numSurfaces == 0 )
- {
- error("Not enough curves selected to align. " +
- "You must select pairs of NURBS curves, " +
- "curves on surface, " +
- "points on curves or curve edit points.");
- }
- else if ( $numCurves == 0 && $numSurfaces == 1 )
- {
- error("Not enough surfaces selected to align. " +
- "You must select pairs of NURBS surfaces " +
- "or surface isoparms.");
- }
- else if ( $numCurves == 1 && $numSurfaces == 1 )
- {
- error("Cannot align a NURBS curve to a NURBS surface. " +
- "You must select objects of the same type.");
- }
- else if ( $numCurves > 1 || $numSurfaces > 1 )
- {
- int $doCurveAlign;
- if ( $numCurves > 1 && $numSurfaces > 1 )
- {
- warning("Only 2 objects of the same type should " +
- "be selected to align. The last selected " +
- "object will be used to determine which objects to use.");
- // figure out which items were selected last and do align on
- // those types of objects only
- string $selectedList[] = `filterExpand -ex true -sm $gSelectNurbsSurfacesBit -sm $gSelectIsoparmsBit -sm $gSelectNurbsCurvesBit -sm $gSelectCurvesOnSurfacesBit -sm $gSelectCurveParmPointsBit`;
- int $numSelected = size($selectedList);
-
- // if the last selected item is the last surface item then do
- // align on surfaces otherwise do align on curves
- if ( $surfacesList[$numSurfaces-1] == $selectedList[$numSelected-1] ) $doCurveAlign = 0;
- else $doCurveAlign = 1;
- }
- else if ( $numCurves > 1 ) $doCurveAlign = 1;
- else $doCurveAlign = 0;
-
- // just use the last 2 selected curves
- //
- if ( $doCurveAlign == 1 && $numCurves > 2 )
- warning("Only 2 curves should be selected to align. " +
- "The last 2 selected curves will be used.");
- else if ( $doCurveAlign == 0 && $numSurfaces > 2 )
- warning("Only 2 surfaces should be selected to align. " +
- "The last 2 selected surfaces will be used.");
-
- string $alignPair[2];
- if ( $doCurveAlign == 1 )
- {
- $cmd = "alignCurve " + $cmd;
- $alignPair[0] = $curvesList[$numCurves-2];
- $alignPair[1] = $curvesList[$numCurves-1];
- }
- else
- {
- $cmd = "alignSurface " + $cmd;
- $alignPair[0] = $surfacesList[$numSurfaces-2];
- $alignPair[1] = $surfacesList[$numSurfaces-1];
- }
-
- if ( $history == 0 && $replaceOriginal == 1 && $attach == 1 )
- {
- // delete history on each input to align cmd (so that command won't
- // force history on)
- //
- string $buffer[];
- tokenize($alignPair[0], ".", $buffer);
- string $itemName = $buffer[0];
- $buffer = `listHistory -pdo 1 $itemName`;
- if ( size($buffer) > 0 )
- {
- // the first item has history so delete it
- //
- warning("History will be deleted on first item for align.");
- evalEcho("delete -ch " + $itemName);
- }
-
- tokenize($alignPair[1], ".", $buffer);
- $itemName = $buffer[0];
- $buffer = `listHistory -pdo 1 $itemName`;
- if ( size($buffer) > 0 )
- {
- // the second item has history so delete it
- //
- warning("History will be deleted on second item for align.");
- evalEcho("delete -ch " + $itemName);
- }
- }
-
- string $results[] = executeCmdOnItems( $cmd, $alignPair );
-
- // select the results.
- //
- int $resultCount = size($results);
- if ( $resultCount > 0 )
- {
- string $selectString;
- $selectString = "select ";
- if ( $replaceOriginal && $attach )
- {
- if ( $history == 0 )
- {
- // delete the second curve since it is no longer required
- evalEcho("delete " + $results[1]);
- }
- else
- {
- // make the second curve an intermediate object (so that
- // the user won't ever see it). Note: can't do "delete"
- // here or else align result will go away due to history
- // on.
- //
- string $resultShapes[] = `listRelatives -s $results[1]`;
- int $shapeCount = size($resultShapes);
- if ( $shapeCount > 0 )
- {
- evalEcho("setAttr " + $resultShapes[0] + ".io true");
- }
- }
- $selectString += $results[0];
- }
- else
- {
- int $i;
- for ( $i = 0; $i < $resultCount; $i++ )
- {
- $selectString += $results[$i];
- $selectString += " ";
- }
- }
- $selectString += ";";
- select -cl;
- eval($selectString);
- }
- }
- }
-